package com.ruoyi.web.controller.tea;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tea.domain.TeaLeaf;
import com.ruoyi.tea.service.ITeaLeafService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 茶叶信息Controller
 * 
 * @author hmx
 * @date 2023-03-15
 */
@RestController
@RequestMapping("/tea/leaf")
public class TeaLeafController extends BaseController
{
    @Autowired
    private ITeaLeafService teaLeafService;

    /**
     * 查询茶叶信息列表
     */
    @PreAuthorize("@ss.hasPermi('tea:leaf:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaLeaf teaLeaf)
    {
        startPage();
        List<TeaLeaf> list = teaLeafService.selectTeaLeafList(teaLeaf);
        return getDataTable(list);
    }

    /**
     * 导出茶叶信息列表
     */
    @PreAuthorize("@ss.hasPermi('tea:leaf:export')")
    @Log(title = "茶叶信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaLeaf teaLeaf)
    {
        List<TeaLeaf> list = teaLeafService.selectTeaLeafList(teaLeaf);
        ExcelUtil<TeaLeaf> util = new ExcelUtil<TeaLeaf>(TeaLeaf.class);
        util.exportExcel(response, list, "茶叶信息数据");
    }

    /**
     * 获取茶叶信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('tea:leaf:query')")
    @GetMapping(value = "/{leafId}")
    public AjaxResult getInfo(@PathVariable("leafId") Long leafId)
    {
        return success(teaLeafService.selectTeaLeafByLeafId(leafId));
    }

    /**
     * 新增茶叶信息
     */
    @PreAuthorize("@ss.hasPermi('tea:leaf:add')")
    @Log(title = "茶叶信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaLeaf teaLeaf)
    {
        return toAjax(teaLeafService.insertTeaLeaf(teaLeaf));
    }

    /**
     * 修改茶叶信息
     */
    @PreAuthorize("@ss.hasPermi('tea:leaf:edit')")
    @Log(title = "茶叶信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaLeaf teaLeaf)
    {
        return toAjax(teaLeafService.updateTeaLeaf(teaLeaf));
    }

    /**
     * 删除茶叶信息
     */
    @PreAuthorize("@ss.hasPermi('tea:leaf:remove')")
    @Log(title = "茶叶信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{leafIds}")
    public AjaxResult remove(@PathVariable Long[] leafIds)
    {
        return toAjax(teaLeafService.deleteTeaLeafByLeafIds(leafIds));
    }
}
